﻿function saveComplaint() {
    var compid = genDynmID();
    var cusName = $('#txtCustomerName').val();
    var cusAddress = $('#txtCusAddress').val();
    var cusRoute = $('#txtRoute').val();
    var cusLocation = $('#txtLocation').val();
    var cusLandmark = $('#txtLandmark').val();
    var cusState = $('#txtState').val();
    var cusPostcode = $('#txtPostcode').val();
    var cusMobile = $('#txtMobile').val();
    var cusEmail = $('#txtEmail').val();
    var prod_cate = $('#ddlBrands option:selected').text();
    var prodName = $('#txtProductName').val();
    var modalNo = $('#txtModalNo').val();
    var compressorNo = $('#txtCompressorNo').val();
    var indoorNo = $('#txtIndoorNo').val();
    var outdoorNo = $('#txtOutdoorNo').val();
    var complaint = $('#txtComplaint').val();
    var shdDt = $('#txtScheduleDt').val();

    if (cusName == "") {
        $('#valCusName').text("Enter the customer name");
    }
    else if (cusAddress == "") {
        $('#valCusAddress').text("Enter the customer address");
    }
    else if (cusRoute == "") {
        $('#valCusRoute').text("Enter the rote name");
    }
    else if (cusLocation == "") {
        $('#valLocation').text("Enter the location/city");
    }
    else if (cusMobile == "") {
        $('#valMobile').text("Enter the customer contact no.");
    }
    else if (prod_cate == "Please Select") {
        $('#valProductCate').text("Select the product category");
    }
    else if (prodName == "") {
        $('#valProductName').text("Enter the product name");
    }
    else if (complaint == "") {
        $('#valComplaintDesc').text("Enter the complaint description");
    }
    else {

        var params = {
            'compid': compid,
            'nme': cusName,
            'adrs': cusAddress,
            'rote': cusRoute,
            'loc': cusLocation,
            'lnmrk': cusLandmark,
            'state': cusState,
            'pcode': cusPostcode,
            'mob': cusMobile,
            'email': cusEmail,
            'pcate': prod_cate,
            'pnme': prodName,
            'mdlno': modalNo,
            'compno': compressorNo,
            'indrno': indoorNo,
            'outdrno': outdoorNo,
            'comp': complaint,
            'shdt': shdDt
        }//regcomplaint.ashx
        var containerDIV = $('#addCustomerForm');
        var opts = { 'isLoadingGif': true, 'container': containerDIV };
        MakeJAjaxCall("../_services/regcomplaint.ashx", params, 'html', fnRegComplaintSuccess, '', '', opts);
    }
}
function fnRegComplaintSuccess(response) {
    if (response == "y") {
        //complaintSummary.aspx
        window.location.href = "../../pages/complaintSummary.aspx";
    }
    else {
        var msg = 'ERROR: Failed to register complaint. Please try again.';
        var opts = { 'AlertText': msg, 'OKTxt': 'OK', 'CancelTxt': 'No', 'okClick': fnSuspendDummy, 'cancelClick': fnSuspendDummy, 'reqCancel': false };
        genAlertPOPUP(opts);
    }

}
function fnSuspendDummy() {

}
function onchangeFilter(obj) {
    if (obj.selectedIndex == 1) {
        $('#showRouteFilter').hide();
        $('#divStatusFilter').hide();
        $('#divCustomerNameFilter').hide();
        $('#showDateFilter').show();
    }
    else if (obj.selectedIndex == 2) {
        $('#showDateFilter').hide();
        $('#divStatusFilter').hide();
        $('#divCustomerNameFilter').hide();
        $('#showRouteFilter').show();
    }
    else if (obj.selectedIndex == 3) {
        $('#showDateFilter').hide();
        $('#showRouteFilter').hide();
        $('#divCustomerNameFilter').hide();
        $('#divStatusFilter').show();
    }
    else if (obj.selectedIndex == 4) {
        $('#showDateFilter').hide();
        $('#showRouteFilter').hide();
        $('#divStatusFilter').hide();
        $('#divCustomerNameFilter').show();
    }
    else {
        $('#showRouteFilter').hide();
        $('#divStatusFilter').hide();
        $('#divCustomerNameFilter').hide();
        $('#showDateFilter').hide();
    }
}